function State(target: object, propertyKey: string) {
  let key = `__${propertyKey}`
  Object.defineProperty(target, propertyKey, {
    get() {
      return this[key]
    },
    set(newValue) {
      console.log(`${propertyKey}的最新值为：${newValue}`);
      this[key] = newValue
    },
    enumerable: true,   // 可枚举性 循环参与遍历
    configurable: true, // 可配置性 允许删除
  })
}

class Person {
  name: string
  @State age: number
  constructor(name: string, age: number) {
    this.name = name
    this.age = age
  }
}

const p1 = new Person('张三', 18)
const p2 = new Person('李三', 28)
p1.age = 30
p2.age = 40


console.log(p1)
console.log(p2)
console.log(p1.age)
console.log(p2.age)
